package com.wqm.step.dao.impl;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.wqm.step.dao.LoadDao;
import com.wqm.step.pojo.Customer;

@Repository
public class LoadDaoImpl extends HibernateDaoSupport implements LoadDao {

	@Autowired
	public void setSuperSessionFactory(SessionFactory factory) {
		super.setSessionFactory(factory);
	}
	
	/**
	 *  演示延迟加载， 并去除web.xml中的延迟加载配置，看看会不会报错
	 *  get 与 load的区别： load延迟加载(用于性能优化)
	 */
	public Customer findLoad() {
		Session session = this.getSessionFactory().getCurrentSession();

		// load方法： springmvc不存在no-session这个错误，所以这个方法可以随便用
		Customer c1 = session.load(Customer.class, 1);
		//Hibernate.initialize(c1);
		
		// get方法：
		//Customer c1 = session.get(Customer.class, 1);

		String name = c1.getName();
		System.out.println(name);
		return c1;
	}

}
